package day0817;

import java.util.Arrays;

/**
 * @Author:galaxy_yan
 * @Date: 2022/8/17
 * @Time: 17:55
 * @Description
 *作业标题(1682)
 * 奇数位于偶数之前
 */
public class text1 {
    public static void main(String[] args) {
        int [] arr={1,2,3,4,5,6};
        func(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void func(int[] arr) {
        //基数位于偶数之前
        int left=0;
        int right= arr.length-1;
        while (left<right){
            while(arr[left]%2==1){
                //如果此时left处为奇数，left移动
                left++;
            }
            while (arr[right]%2==0){
                right--;
            }
            if(left<right){
                swap(arr, left, right);
            }
        }
    }

    public static void swap(int[] arr,int left,int right){
        int tmp=arr[left];
        arr[left]=arr[right];
        arr[right]=tmp;
    }
}
